﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter22.ViewModel
{
    using System.Globalization;
    using System.Windows.Data;
    using System.IO;
    using System.Windows.Media.Imaging;

    [ValueConversion(typeof(BitmapImage), typeof(string))]
    public class ImagePathConverter : IValueConverter
    {
        private string imagesDir = "Images";
        private string imageDirectory = Directory.GetCurrentDirectory();

        public string ImageDirectory
        {
            get { return imageDirectory; }
            set { imageDirectory = value; }
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string imagePath = Path.Combine(ImageDirectory, imagesDir, (string)value);
            return new BitmapImage(new Uri(imagePath));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
